[Git] 02. Commit

Commit

Track all files in this repository

$ git add --all

Track only all files in current path, including of sub-directories

$ git add .

Remove the file and track it

$ git rm xxx.file

Which equals to

$ del xxx.file
$ git add xxx.file

Remove the file and untrack it

Stage a file for removal, but it won’t be removed from the working dir. The file will be shown as untracked.

$ git rm --cached xxx.file

Rename the file and track it

$ git mv xxx.file yyy.file

Which equals to

mv xxx.file yyy.file
git add --all

Untrack the file already committed

$ git rm xxx.file --cached

Amend the last commit’s message

$ git commit --amend -m "Refine message"

Add tracked file to the last commit

$ git add zzz.html
$ git commit --amend --no-edit

Update the commit history

$ git rebase -i {begin_sha-1_code}

which will open the default git editor

Table of contents
  1. 1. Commit
    1. 1.1. Track all files in this repository
    2. 1.2. Track only all files in current path, including of sub-directories
    3. 1.3. Remove the file and track it
    4. 1.4. Remove the file and untrack it
    5. 1.5. Rename the file and track it
    6. 1.6. Untrack the file already committed
    7. 1.7. Amend the last commit’s message
    8. 1.8. Add tracked file to the last commit
    9. 1.9. Update the commit history